/** <!--------------------------------------------------------------------------------------------->
 * @file RevGraph.h
 *
 * GSvn - A Graphical Client for SVN
 * Copyright (C) 2012  Karl Krach, gsvn@bluespirit.la
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 <!---------------------------------------------------------------------------------------------> */

#ifndef REVGRAPH_H
#define REVGRAPH_H

// -- includes --
#include <QObject>
#include <QGraphicsView>
#include "RevModelItem.h"
#include "SvnRevisionIdentifier.h"
#include "RevGraphItemMap.h"
#include "RevGraphBranchMap.h"

// --- forward declarations ---
class RevGraphBranch;

// --- namespaces ---
// --- defines ---
typedef int Revision;
#ifndef QSP
#define QSP QSharedPointer
#endif



/** <!--------------------------------------------------------------------------------------------->
 * Widget to visualize the revision in a two dimensional graph.
 *
 * @author	Karl Krach, <gsvn@bluespirit.la>
 * @since	2012-01-21
 <!---------------------------------------------------------------------------------------------> */
class RevGraph : public QGraphicsView
{
	Q_OBJECT

	/* Con-/Destructors */
public:

	/** <!----------------------------------------------------------------------------------------->
	 * Creates the RevGraph object
	 <!-----------------------------------------------------------------------------------------> */
	RevGraph();

	/** <!----------------------------------------------------------------------------------------->
	 * Deletes the RevGraph object
	 <!-----------------------------------------------------------------------------------------> */
	virtual ~RevGraph();


	/* Public Methods */
public:

	/** <!----------------------------------------------------------------------------------------->
	 * Visualizes the given node and sets the focus on it
	 <!-----------------------------------------------------------------------------------------> */
	void Visualize( const SvnRevisionIdentifier& rRevID );


	/* Signals */
signals:

	/** <!----------------------------------------------------------------------------------------->
	 * Signal is emitted, when a revision with the given ID is requested (e.g. after scrolling)
	 <!-----------------------------------------------------------------------------------------> */
	void SI_RevisionRequested( const SvnRevisionIdentifier& rRevID );


	/* Public Slots */
public slots:

	/** <!----------------------------------------------------------------------------------------->
	 * Updates the given model item or paint it to the screen, if it was not created before.
	 <!-----------------------------------------------------------------------------------------> */
	void SL_UpdateRevision( QSP<RevModelItem> pRevModelItem );

	/** <!----------------------------------------------------------------------------------------->
	 * Updates the given branch (branch index is used by RevItemModel as index)
	 <!-----------------------------------------------------------------------------------------> */
	void SL_UpdateBranch( BranchIndex iBranchIndex, QString strBranchName );

	/** <!----------------------------------------------------------------------------------------->
	 * Visualizes the status message on the screen
	 <!-----------------------------------------------------------------------------------------> */
	void SL_VisualizeStatus( const QString& strStatus );


	/* Members */
private:

	/** <!----------------------------------------------------------------------------------------->
	 * ID on which the graph should be centered
	 <!-----------------------------------------------------------------------------------------> */
	int m_iCenterRev;

	/** <!----------------------------------------------------------------------------------------->
	 * Map of items (this reference is needed to update existing items)
	 <!-----------------------------------------------------------------------------------------> */
	RevGraphItemMap m_aItemMap;

	/** <!----------------------------------------------------------------------------------------->
	 * Map of branch objects (e.g. contains all items)
	 <!-----------------------------------------------------------------------------------------> */
	RevGraphBranchMap m_aBranches;
};

#endif // REVGRAPH_H
